package com.jqb.struts2lab01.action;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

public class MultiFileUploadAction {
	private File[] userfile;
	private String[] userfileFileName;

	public String execute() {
		String realpath = ServletActionContext.getServletContext().getRealPath("/userupload");
		if (userfile != null) {
			for (int i = 0; i < userfile.length; i++) {
				File file = new File(new File(realpath), userfileFileName[i]);
				if (file.exists())
					file.mkdirs();
				try {
					FileUtils.copyFile(userfile[i], file);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return "success";
	}

	public File[] getUserfile() {
		return userfile;
	}

	public void setUserfile(File[] userfile) {
		this.userfile = userfile;
	}

	public String[] getUserfileFileName() {
		return userfileFileName;
	}

	public void setUserfileFileName(String[] userfileFileName) {
		this.userfileFileName = userfileFileName;
	}

}
